namespace Stee.Cap8.Communication.WebApiSample.Controllers
{
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Logging;
    using Stee.CAP8.Communication.GrpcInterface;
    using Stee.CAP8.Communication.ServiceSample;
    using Stee.CAP8.Service.Shared.Converters;

    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private readonly ILogger<WeatherForecastController> logger;
        private readonly Greeter.GreeterClient greeterClient;
        //public WeatherForecastController(ILogger<WeatherForecastController> llogger,IServiceProvider serviceProvider)
        //{
        //    logger = llogger;
        //    greeterClient = Cap8GrpcClientFactory.GetClient<Greeter.GreeterClient>(serviceProvider);
        //}
        public WeatherForecastController(ILogger<WeatherForecastController> llogger, Greeter.GreeterClient gclient)
        {
            logger = llogger;
            greeterClient = gclient; //Cap8GrpcClientFactory.GetClient<Greeter.GreeterClient>(serviceProvider);
        }

        [HttpGet]
        public async Task<PersonInfo> GetPerson()
        {
            GrpcClientOption.Token = "tester";
            
            var person = await greeterClient.GetPersonInfoAsync(new EmptyMessage(), GrpcClientOption.GetGrpcHeader());
            return ProtobufConvertor.ToObject<PersonInfo>(person); 
        }
    }
}
